package com.google.code.p.narcissus.core.remote;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Serializable;

import javax.imageio.ImageIO;

public class SerializableImage implements Serializable {

	private static final long serialVersionUID = 1L;

	private byte[] imageData;

	public SerializableImage(BufferedImage image) throws IOException {
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream(image.getWidth() * image.getHeight());
		ImageIO.write(image, "png", outputStream);
		imageData = outputStream.toByteArray();
	}

	public BufferedImage getBufferedImage() throws IOException {
		return ImageIO.read(new ByteArrayInputStream(imageData));
	}
}
